//
//  TAMTSettingController.swift
//  TAMeetApp
//
//  Created by Admin on 2024/12/3.
//

import UIKit

class TAMTSettingController: UIViewController, UITableViewDelegate, UITableViewDataSource {
    
    lazy var appDictArray:Array = {
        let dict1 = ["title":"账户与安全", "value":""]
        let dict2 = ["title":"黑名单", "value":"九月"]
        let dict3 = ["title":"开启推送", "value":"9464525", "type":"1"]
        
        let dict4 = ["title":"分享好友", "value":"女"]
        let dict5 = ["title":"清理缓存", "value":""]
        
        return [dict1, dict2, dict3, dict4, dict5]
    }()
    
    private lazy var tableView: UITableView = {
        let apple = UITableView(frame: self.view.bounds, style: .plain)
        apple.autoresizingMask = [.flexibleWidth, .flexibleHeight]
        apple.contentInsetAdjustmentBehavior = .never
        apple.estimatedRowHeight = 0
        apple.rowHeight = 55
        apple.delegate = self
        apple.dataSource = self
        apple.separatorStyle = .none
        apple.tableFooterView = UIView(frame: .zero)
        apple.showsVerticalScrollIndicator = false
        apple.showsHorizontalScrollIndicator = false
        apple.backgroundColor = UIColor.white
        apple.register(UITableViewCell.self, forCellReuseIdentifier: "cell1")
        return apple
    }()
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        
        self.navigationController?.setNavigationBarHidden(false, animated: true)
    }

    override func viewDidLoad() {
        super.viewDidLoad()

        self.navigationItem.title = "设置中心"
        view.backgroundColor = .white
        
        view.addSubview(tableView)
        tableView.snp.makeConstraints { make in
            make.top.equalTo(view.safeAreaLayoutGuide.snp.top)
            make.bottom.equalTo(view.safeAreaLayoutGuide.snp.bottom)
            make.leading.trailing.equalToSuperview()
        }
    }
    
    // 返回表格的行数
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return appDictArray.count
    }
    
    // 返回表格单元格的内容
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let dict = appDictArray[indexPath.row]
        let cell = tableView.dequeueReusableCell(withIdentifier: "cell1", for: indexPath) as UITableViewCell
        cell.textLabel?.text = dict["title"]
        return cell
    }
    
    // MARK: - UITableViewDelegate
    
    // 选中某一行时的响应方法
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        // 可以进行跳转等操作
        tableView.deselectRow(at: indexPath, animated: true)  // 取消选中状态
        
        let dict = appDictArray[indexPath.row]
        let title = dict["title"]
        
        if title == "黑名单" {
            let page = TAMTHaHaController()
            page.navigationItem.title = title
            self.navigationController?.pushViewController(page, animated: true)
        }
    }

}
